home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World Komputer 2010 April
/
PCWorld0410.iso
/
pluginy Firefox
/
1035
/
1035.xpi
/
chrome
/
1clickweather.jar
/
content
/
1clickweather
/
js
/
data
/
datasource.js
next >
Wrap
Text File
|
2010-01-04
|
7KB
|
255 lines
// � 2005 The Weather Channel Interactive, Inc. All Rights Reserved.
// handle the obs data
var oDataSources = Array();
function oDataSourcesStub(){
this.Data = {};
this.oldData = {};
this.run = 0;
this.PanelList = Array();
this.Timer = null;
this.Scheduler = Components.classes["@mozilla.org/timer;1"].createInstance(Components.interfaces.nsITimer);
this.Interval = 10;
this.XY = Array();
this.lastUpdate = null;
this.nextUpdate = null;
this.Id = function(id){
this.id = id; // id of the object to associate with the xul interface
}
this.Url = function(url){
this.url = url;
debug('setting url[' + this.id + ']: ' + this.url);
}
this.getID = function(){
return(this.id);
}
// Update() is called periodically to update the data in the object
this.Update = function(){
if(this.url){
try{
debug('data update: ' + this.url);
// debugLog('data update: ' + this.url);
var xmlRequest = new XMLRequest();
xmlRequest.setParser(this);
xmlRequest.setUrl(this.url);
var response = xmlRequest.Get();
this.UpdateTime();
// tracking
var track = new weather_trackingSystem();
track.DataPullTracking(); // 17/1 data pull tracking
// this use a internal logic
track.DailyUpdateTracking(); // Daily tracking
}catch(e){
debugLog("error in update: " + this.id + " " + e);
}
}else if(this.Running){
debugLog("data update already running: " + this.id);
}
}
this.Finish = function(){
debugLog("finished data update: " + this.id);
}
this.Shutdown = function(){
debugLog("shutdown: " + this.id);
this.Scheduler.cancel();
}
this.setInterval = function(i){
this.Interval = i;
}
this.Start = function(){
debug('start: ' + this.url);
this.Scheduler.initWithCallback(this, (1000 * 60 * this.Interval), Components.interfaces.nsITimer.TYPE_REPEATING_SLACK);
}
this.notify = function(aTimer){
// debugLog("notify: " + this.id + " " + aTimer.delay);
this.Update();
}
this.UpdateTime = function(objName){
var date = new Date();
var d = new Date(date.getTime() + (1000 * 60 * this.Interval));
this.nextUpdate = d.toLocaleString();
this.lastUpdate = date.toLocaleString();
}
// if there is an error from he XMLRequestNonBlocking call, call this method
this.parseError = function(errCode){
debugLog('parseError: ' + errCode + " " + this.id);
// GlobalError.Show();
}
this.Dump = function(asText){
if(asText){
return(Dumper(this));
}else{
DumperAlert(this);
}
}
this.Register = function(panelID){
this.PanelList.push(panelID);
}
this.unRegister = function(panelID){
for(var i in this.PanelList){
if(this.PanelList[i] == panelID){
break;
}
}
ToolbarContainers[this.PanelList[i]].Hide();
this.PanelList.splice(i, 1);
}
this.iconPath = function(name, type, size){
try{
var path = "";
if(type == "moon"){
path = GlobalAppConfig.getDataByName(this.id).getMoonPhaseIcons().getBase() + name + '.gif';
}else{
if(size == "large"){
path = GlobalAppConfig.getDataByName(this.id).getWxIcons().getBase() + GlobalAppConfig.getDataByName(this.id).getWxIcons().getLarge() + name + '.png';
}else{
path = GlobalAppConfig.getDataByName(this.id).getWxIcons().getBase() + GlobalAppConfig.getDataByName(this.id).getWxIcons().getSmall() + name + '.png';
}
}
return(path);
}catch(e){
return(null);
}
}
this.parseHeader = function(xmlDoc){
try{
var xml = xmlDoc.getElementsByTagName('dnam')[0].firstChild.nodeValue;
if(xml){
this.Data['dnam'] = xml;
}
var xml = xmlDoc.getElementsByTagName('suns')[0].firstChild.nodeValue;
if(xml){
this.Data['suns'] = xml;
}
var xml = xmlDoc.getElementsByTagName('tm')[0].firstChild.nodeValue;
if(xml){
this.Data['tm'] = xml;
}
var xml = xmlDoc.getElementsByTagName('ut')[0].firstChild.nodeValue;
if(xml){
this.Data['ut'] = xml;
}
var xml = xmlDoc.getElementsByTagName('ud')[0].firstChild.nodeValue;
if(xml){
this.Data['ud'] = xml;
}
var xml = xmlDoc.getElementsByTagName('us')[0].firstChild.nodeValue;
if(xml){
this.Data['us'] = xml;
}
var xml = xmlDoc.getElementsByTagName('up')[0].firstChild.nodeValue;
if(xml){
this.Data['up'] = xml;
}
var xml = xmlDoc.getElementsByTagName('ur')[0].firstChild.nodeValue;
if(xml){
this.Data['ur'] = xml;
}
var xml = xmlDoc.getElementsByTagName('lsup')[0].firstChild.nodeValue;
if(xml){
this.Data['lsup'] = xml;
}
}
catch(e){
debug('header error: ' + this.id + " " + e);
}
}
this.getLink = function(index, daynum){
var linkUrl = GlobalAppConfig.getLinkByID(index).getURL();
linkUrl = linkUrl.replace(/LOCIDTAG/g, GlobalUserConfig.getAllProfiles().getDefaultProfile().getSetup().getLocation().getLocID());
if(daynum){
linkUrl = linkUrl.replace(/DAYNUMTAG/g, daynum);
}
return(linkUrl);
}
this.setScreenXY = function(w, h){
// we have to locate the tooltip to make sure we don't loose some of it off the screen
// with severe weather, we have a kink in the way we do location that is different from
// the global error handler.
// if there is enough space to fill in the tooltip, make it relative to the swa icon,
// otherwise, force it just on the right side
try{
var newXY = Array();
var xy = ToolbarContainers['Day4'].getScreenXY();
var swa = ToolbarContainers['SWA'].getScreenXY();
if((xy[0] - swa[0]) > w){
newXY[0] = swa[0];
}else{
newXY[0] = xy[0] - w;
}
if(xy[1] < h){
newXY[1] = xy[1];
}else{
newXY[1] = xy[1] - h;
}
this.XY = newXY;
}catch(e){
debugLog("error in setting screen location: " + e);
}
}
}
function dataUpdate(id){
if(typeof(DataContainers[id]) != "undefined"){
// debugLog("sending update: " + id);
var result = DataContainers[id].Update();
return result;
}
}
jsInclude("chrome://1clickweather/content/js/data/obs.js");
jsInclude("chrome://1clickweather/content/js/data/fcst.js");
jsInclude("chrome://1clickweather/content/js/data/swa.js");